<h2>Libros</h2>

<div class="row span12">
	<form action="index.php" method="GET">
		<input type="hidden" name="module" value="books" />
		<select name="categories_id" onchange="this.form.submit();">
		<option value="0" <?php echo $categories_id==0 ? 'selected' : '';?>>Seleccionar una categor&iacute;a</option>
<?php foreach($categories as $c):?>
		<option value="<?php echo $c->id;?>" <?php echo $categories_id==$c->id ? 'selected' : '';?>><?php echo $c->name;?></option>
<?php endforeach;?>
		</select>
	</form>
</div>

<?php if(!empty($text_success)):?>
<p class="text-success"><?php echo $text_success;?></p>
<?php endif;?>

<?php if(!empty($text_error)):?>
<p class="text-error"><?php echo $text_error;?></p>
<?php endif;?>

<div class="row span12"><a class="btn btn-primary" href="index.php?module=books&submodule=new">Agregar nuevo libro</a></div>

<table class="table table-striped">
	<thead>
	<tr>
		<th>#</th>
		<th>Nombre</th>
		<th></th>
	</tr>
	</thead>
	<tbody>
<?php $i=0;foreach($books as $b):?>
	<tr>
		<td><?php echo ++$i;?></td>
		<td><?php echo $b->name;?></td>
		<td><a class="btn btn-primary" href="index.php?module=books&submodule=edit&id=<?php echo $b->id;?>">Editar</a>&nbsp;<a class="btn btn-danger" onclick="if(!confirm('Eliminar este libro?')) return false;" href="index.php?module=books&action=delete&id=<?php echo $b->id;?><?php echo !empty($categories_id) ? '&categories_id=' . $categories_id : '';?>">Eliminar</a></td>
	</tr>
<?php endforeach;?>
	</tbody>
</table>
